/* 
 * File:   nfs.h
 * Author: lishang
 *
 * Created on 2018年4月10日, 下午1:48
 */


#include "FileRestore.h"
#include <stdio.h>
#include<sys/stat.h> 
#include <iconv.h>
#include <string>
#ifndef NFS_H
#define NFS_H

class Nfs {
public:    
    static bool debug;
//    Nfs(){}
//    Nfs(map<string,int>config){
//        map<string,int>::iterator i;
//        for (i=config.begin(); i != config.end(); i++) {
//            this[i->first]=i->second;
//        }
//    }
    virtual long next()=0;
    virtual FileInode getInode(long pos=0)=0;
    virtual string getData(FileInode file,long start=0,long len=0)=0;
    virtual void dump(long pos,long size=0xFF)=0;
    
    virtual bool setJumpM(int)=0;
    virtual  DiskInfo getDiskInfo()=0;
    
    
    static char *parseUNICODE(char *a, int size) {
        size *= 2;
        char filename[5000]; //char *filename=(char *)malloc(size*2);   memset(filename,0,sizeof(filename)); 
        char *b = filename;

        iconv_t cd = iconv_open("UTF-8", "UNICODE//IGNORE");
        size_t il = size, ol = 1024;
        size_t ret = iconv(cd, &a, &il, &b, &ol);
        iconv_close(cd);
        *b = '\0';

        char *fileName = (char *) malloc(strlen(filename) + 1);
        memset(fileName, 0, sizeof (fileName));
        strcpy(fileName, filename);
        return fileName;
    }
    
    /**
     * 数字型字符串 返回数字值
     * @param s 字符串指针 
     * @param len 长度
     * @return 
     */
    static inline long strLenVal(char *s, int len) {
        char num[100];
        memset(num, 0, sizeof (num));
        memcpy(num, s, len);
        return *((long *) &num);
    }
    
    template <typename vtype>
    void dumpVector(vector<vtype> *v,void (*p)(vtype *t),int max=500,int start=0){
        int size=v->size();
        int i,n;
        for (i=0,n=0;i<size && n<max;i++) {
            if(i < start) continue;
            n++;
            vtype it=v->at(i);
            cout << i+1 <<". ";
            (p)(&it);
        }
        if(n<size) printf("\n...(sum:%d)\n",size);
            
    }
    
    template <typename vtype>
    void dumpVector(vector<vtype> *v,int max=500,int start=0){
        int size=v->size();
        int i,n;
        for (i=0,n=0;i<size && n<max;i++) {
            if(i < start) continue;
            n++;
            vtype it=v->at(i);
            cout << i+1 <<". ";
            cout << it << endl;            
        }
        if(n<size) printf("\n...(sum:%d)\n",size);
    }
    
    
    template <typename vTypeKey,typename vTypeVal>
    void dumpMap(map <vTypeKey, vTypeVal> *m){
                typename map <vTypeKey, vTypeVal>::iterator mit;
                for (mit = m->begin(); mit != m->end(); mit++) {
                    cout << "   " << (*mit).first << " " << (*mit).second << endl;
                }
    }
    
    void test(){
        die("ok");
    }
    
private:

};

bool Nfs::debug=false;

#include "nfs/Ntfs.cpp"
#include "nfs/Ext4.cpp"


#endif /* NFS_H */

